﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Library.Bll;

namespace HanhuaMicroCredit.BLL
{
    public static class SysMenu
    {
        //资料名称
        public static List<Dictionary<string, object>> getFunction(string key, string val)
        {
            string conditions = string.Format(" {0}={1} and IsValid= 1 ", key, val);
            return CommonBLL.GetList("Sys_IBFunctions", "id as id,Name as name", " MenuId asc ", conditions);
        }

        /// <summary>
        /// 转化树
        /// </summary>
        public static List<Dictionary<string, object>> getTree(List<Dictionary<string, object>> list,string pid,int node)
        {
            List<Dictionary<string, object>> list_node=new List<Dictionary<string,object>>();
            foreach (Dictionary<string, object> dic_node in list)
            {
                if (dic_node["pid"].ToString() == pid)
                {
                    dic_node.Add("node", node);
                    list_node.Add(dic_node);
                    List<Dictionary<string, object>> list_remove = new List<Dictionary<string, object>>(list);
                    list_remove.Remove(dic_node);
                    List<Dictionary<string, object>> list_rt=getTree(list_remove, dic_node["id"].ToString(),node+1);
                    if (list_rt != null)
                    {
                        foreach (Dictionary<string, object> dic_rt in list_rt)
                        {
                            list_node.Add(dic_rt);
                        }
                    }
                }
            }
            if (list_node.Count > 0)
            {
                return list_node;
            }
            else
            {
                return null;
            }
        }
    }
}
